package com.dd.ent.car.ui.user.note;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.dd.ent.car.R;
import com.dd.ent.car.common.bean.note.Note;
import com.dd.ent.car.common.xrichtext.ui.NewActivity;
import com.dd.ent.car.common.xrichtext.ui.NoteActivity;

/**
 * Created by aqu-spring on 16/8/17.
 */
public class NoteItemView extends FrameLayout implements View.OnClickListener {

    private int position;
    private Note note;
    private TextView title;
    private TextView content;
    private TextView time;
    private ImageView imgEdit;

    public NoteItemView(Context context) {
        super(context);
        init(context);
    }

    public NoteItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context) {
        View root = LayoutInflater.from(context).inflate(R.layout.item_note_list, this, true);
        title = (TextView) root.findViewById(R.id.tv_list_title);
        content = (TextView) root.findViewById(R.id.tv_list_summary);
        time = (TextView) root.findViewById(R.id.tv_list_time);
        imgEdit = (ImageView) root.findViewById(R.id.img_edit);
        imgEdit.setOnClickListener(this);
        root.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                NoteActivity.startSelf(getContext(), NoteActivity.From.DETAILS, note);
            }
        });
    }

    public void refreshData(int position, Note item) {
        this.position = position;
        note = item;
        title.setText(note.getTitle());
        content.setText(note.getContent());
        time.setText(note.getCreateTime());
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.img_edit:
                NewActivity.startSelf(getContext(), 1,note);
                break;
            default:
                break;
        }
    }
}
